package my.sc.product.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import entity.Product;
import my.sc.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.net.idn.Punycode;

import java.security.PublicKey;

/**
 * @author ：Q大侠
 * @date ：Created in 2022/11/17 21:36
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @GetMapping("getById/{pid}")
    @SentinelResource("hot")//如果使用热点参数限流，默认对springmvc资源无效
    public Product getById(@PathVariable Long pid){
        if (pid==1){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return productService.findById(pid);
    }

    @Value("${student.name}")
    private String name;

    @GetMapping("getInfo")
    public String getInfo(){
        return "姓名:"+name;
    }

    @GetMapping("write")
    public String write(){
        return "写操作!";
    }
    @GetMapping("read")
    public String read(){
        return "read操作!";
    }
}
